﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Telerik.Windows.Controls.TimeBar;
namespace Daq.Converters
{
    public class HourFormatterProvider : IIntervalFormatterProvider
    {
        private static Func<DateTime, string>[] formatters;
        private Func<DateTime, string>[] intervalSpanFormatters;
        static HourFormatterProvider()
        {
            formatters = new Func<DateTime, string>[]
            {
                 date => $"{date.Hour}h",
                 date => date.ToString("HH")
            };
        }
        public Func<DateTime, string>[] GetFormatters(IntervalBase interval)
        {
            return formatters;
        }
        public Func<DateTime, string>[] GetIntervalSpanFormatters(IntervalBase interval)
        {
            if (this.intervalSpanFormatters == null)
            {
                this.intervalSpanFormatters = new Func<DateTime, string>[]
                {
                    date => String.Format("{0} ~ {1}", date.ToString("H:mm"),
                    interval.IncrementByCurrentInterval(date).ToString("H:mm"))
                };
            }
            return this.intervalSpanFormatters;
        }
    }
    public class MinuteFormatterProvider : IIntervalFormatterProvider
    {
        private static Func<DateTime, string>[] formatters;
        private Func<DateTime, string>[] intervalSpanFormatters;
        static MinuteFormatterProvider()
        {
            formatters = new Func<DateTime, string>[]
            {
                 date => date.ToString("H:mm"),
                 date => date.ToString("mm")
            };
        }
        public Func<DateTime, string>[] GetFormatters(IntervalBase interval)
        {
            return formatters;
        }
        public Func<DateTime, string>[] GetIntervalSpanFormatters(IntervalBase interval)
        {
            if (this.intervalSpanFormatters == null)
            {
                this.intervalSpanFormatters = new Func<DateTime, string>[]
                {
                    date => String.Format("{0} ~ {1}", date.ToString("H:mm"),
                    interval.IncrementByCurrentInterval(date).ToString("H:mm"))
                };
            }
            return this.intervalSpanFormatters;
        }
    }
    public class DayFormatterProvider : IIntervalFormatterProvider
    {
        private static Func<DateTime, string>[] formatters;
        private Func<DateTime, string>[] intervalSpanFormatters;
        static DayFormatterProvider()
        {
            formatters = new Func<DateTime, string>[]
            {
                 date => $"{date.Day}d",
                 date => date.ToString("dd")
            };
        }
        public Func<DateTime, string>[] GetFormatters(IntervalBase interval)
        {
            return formatters;
        }
        public Func<DateTime, string>[] GetIntervalSpanFormatters(IntervalBase interval)
        {
            if (this.intervalSpanFormatters == null)
            {
                this.intervalSpanFormatters = new Func<DateTime, string>[]
                {
                    date => String.Format("{0} ~ {1}", date.ToString("H:mm"),
                    interval.IncrementByCurrentInterval(date).ToString("H:mm"))
                };
            }
            return this.intervalSpanFormatters;
        }
    }
}
